package com.kmxd.ams.core.util;

import cn.hutool.core.map.MapUtil;
import com.google.common.collect.Lists;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * excel 通用类
 *
 * @author nickbi
 */
public class ExcelUtil {
  /**
   * 封装数据
   *
   * @param mapList
   * @param keys
   * @return
   */
  public static List<List<Object>> detail(List<Map<String, Object>> mapList, List<String> keys) {
    List<List<Object>> list = new ArrayList<List<Object>>();
    mapList.forEach(
        map -> {
          List<Object> objectList = Lists.newArrayList();
          keys.forEach(
              key -> {
                String str = MapUtil.getStr(map, key, "");
                objectList.add(str);
              });
          list.add(objectList);
        });
    return list;
  }

  public static List<List<String>> strDetail(List<Map<String, String>> mapList, List<String> keys) {
    List<List<String>> list = new ArrayList<List<String>>();
    mapList.forEach(
        map -> {
          List<String> objectList = Lists.newArrayList();
          keys.forEach(
              key -> {
                String str = MapUtil.getStr(map, key, "");
                objectList.add(str);
              });
          list.add(objectList);
        });
    return list;
  }

  /**
   * 设置表头
   *
   * @param header
   * @return
   */
  public static List<List<String>> head(List<String> header) {
    List<String> head0 = null;
    List<List<String>> list = new LinkedList<List<String>>();
    for (String str : header) {
      head0 = Lists.newArrayList();
      head0.add(str);
      list.add(head0);
    }
    return list;
  }
}
